home *** CD-ROM | disk | FTP | other *** search
- Path: detroit.freenet.org!ab411
- From: ab411@detroit.freenet.org (David R. Conrad)
- Newsgroups: comp.lang.c
- Subject: Re: 6 byte real to double; How?
- Date: 9 Mar 1996 13:11:36 GMT
- Organization: Greater Detroit Free-Net, Detroit, MI
- Message-ID: <4hs028$apu@detroit.freenet.org>
- References: <4gg88a$3oi@aphex.direct.ca> <3128306A.21F@hsc.unt.edu>
- Reply-To: ab411@detroit.freenet.org (David R. Conrad)
- NNTP-Posting-Host: detroit.freenet.org
-
-
- >In article <3128306A.21F@hsc.unt.edu>, sfogoros@hsc.unt.edu says...
- >>
- >>I have a lot of data files that were created by a pascal program. The
- >>data is stored as 'file of real' meaning that each floating point value
- >>is stored in six bytes. I need to access this data from a c program
- >>(borland). I would like any assistance you could provide. I guess what
- >>I need is a canned function that would take a 6 byte string (actually the
- >>real), and return a double.
-
- I'm going to go out on a limb (okay, so it's a pretty short limb) and
- assume that this file was created with Turbo Pascal. The format of the
- TP real data type, according to my TP 5.5 Reference Guide:
-
- # A 6-byte (48-bit) Real number is divided into three fields:
- #
- # 1 39 8 width
- # +---+---------------+---------+
- # | s | f | e |
- # +---+---------------+---------+
- # msb lsb msb lsb order
- #
- # The value v of the number is determined by
- #
- # if 0 < e <= 255, then v = (-1)^s * 2^(e-129) * (1.f).
- # if e = 0, then v = 0.
- #
- # Note: The real type cannot store denormals, NaNs, and infinities.
- # Denormals become zero when stored in a real, and NaNs and infinities
- # produce an overflow error if an attempt is made to store them in a real.
-
- Note that in the first line of the formula for v they had "s" and "(e-129)"
- as actual superscripts, which I've indicated with carats (^).
-
- In other words, a TP real has a sign bit, 39 mantissa bits with an implied
- one bit in front of them, and an 8 bit exponent in "excess 129" notation.
-
- I assume that between the diagram above, my explanation, and the
- pseudo-code they gave for determining the value, you'll have no trouble
- writing your C function. You probably would have gotten an answer
- quicker by posting to comp.lang.pascal.
-
- --
- David R. Conrad, conrad@detroit.freenet.org PGP key on GDFN Hardware and
- http://detroit.freenet.org/staff/conrad home page Software Committee
- "If you can't say 'fuck', you can't say 'fuck the government'." --Lenny Bruce
- "We had to destroy the Global Electronic Village in order to save it." --Exon
-